package com.itfitness.ftlib.widget.tabview;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itfitness.ftlib.R;

/**
 * @ProjectName: FitnessLib
 * @Package: com.itfitness.ftlib.widget.tabview
 * @ClassName: FTabItemView
 * @Description: java类作用描述 大图的Item
 * @Author: 作者名
 * @CreateDate: 2020/11/22 10:06
 * @UpdateUser: 更新者：itfitness
 * @UpdateDate: 2020/11/22 10:06
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class FTabBigImageItemView extends FTabBaseItemView{
    private ImageView imgTabicon;
    private TextView tvTabname;

    public FTabBigImageItemView(@NonNull Context context) {
        this(context, null);
    }

    public FTabBigImageItemView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FTabBigImageItemView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View.inflate(context, R.layout.item_ftab_big, this);
        initView();
    }

    private void initView() {
        imgTabicon = (ImageView) findViewById(R.id.img_tabicon);
        tvTabname = (TextView) findViewById(R.id.tv_tabname);
    }

    @Override
    protected void setData(FTabBaseItemBean fTabBaseItemBean) {
        super.setData(fTabBaseItemBean);
    }

    public void setSelect(boolean isSelect) {
        if (fTabBaseItemBean == null) {
            return;
        }
        if (isSelect) {
            if (fTabBaseItemBean.getSelectedImageRes() != null) {
                imgTabicon.setImageResource(fTabBaseItemBean.getSelectedImageRes());
            } else if(!TextUtils.isEmpty(fTabBaseItemBean.getDefaultImageUrl())){
                Glide.with(getContext()).load(fTabBaseItemBean.getSelectedImageUrl()).into(imgTabicon);
            }
            tvTabname.setText(fTabBaseItemBean.getSelectedTabName());
            tvTabname.setTextColor(fTabBaseItemBean.getSelectedTabTextColor());
        } else {
            if (fTabBaseItemBean.getDefaultImageRes() != null) {
                imgTabicon.setImageResource(fTabBaseItemBean.getDefaultImageRes());
            } else if(!TextUtils.isEmpty(fTabBaseItemBean.getDefaultImageUrl())){
                Glide.with(getContext()).load(fTabBaseItemBean.getDefaultImageUrl()).into(imgTabicon);
            }
            tvTabname.setText(fTabBaseItemBean.getDefaultTabName());
            tvTabname.setTextColor(fTabBaseItemBean.getDefaultTabTextColor());
        }
    }
}
